<?php
    $id_mon=$_GET['id'];
    $data = $db->GetRow("SELECT * FROM monhoc WHERE id=".$id_mon);
    $mon = $data['ten'];
    $khoi = $data['id_khoi'];
    $templ = new XTemplate('sites/tpml/qlmon/edit.html');
    $sql = "SELECT * FROM khoi";
    $array = $db->Execute($sql);
    foreach($array as $val){
        $templ->insert_loop('INSERT.LOOP',array('LOOP'=>$val));
        if($khoi == $val['id_khoi']){
            $templ->assign('selected','selected');
        }
    }
    if($_POST){
        $tenmon = $_POST['tenmonhoc'];
        $khoi = $_POST['tenkhoi'];
        $db->Execute("UPDATE monhoc SET ten='$tenmon',id_khoi=$khoi WHERE id=".$id_mon);
        header('Location: index.php');
    }
    $templ->assign('mon',$mon);
    $templ->assign('tit','Sửa môn học');
    $templ->parse('INSERT');
    $maincontent = $templ->text('INSERT');
?>